package net.starwifi.duobao.web.member;


import net.starwifi.duobao.entity.Member;
import net.starwifi.duobao.mvc.BaseController;
import net.starwifi.duobao.mvc.Message;
import net.starwifi.duobao.service.AreaService;
import net.starwifi.duobao.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;


/**
 * 用户信息
 * Created by ruo on 2015/7/18.
 */
@RequestMapping(value = "/member")
@Controller("wapMemberMainController")
public class MemberInfoController extends BaseController {

    @Autowired
    MemberService memberService;


    /**
     * 查看
     */
    @ResponseBody
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public Object view() {
        return Message.createMessage(Message.success("登陆成功"), new HashMap<String, Object>() {{
            put("entity",memberService.getCurrent());
        }});
    }

    /**
     * 修改性别
     */
    @ResponseBody
    @RequestMapping(value = "/edit_sex", method = RequestMethod.POST)
    public Object topTwo(int sex) {
        Member sessionMember=memberService.getCurrent();
        Member dataMember=memberService.find(sessionMember.getId());
        dataMember.setGender(sex);
        memberService.update(dataMember);
        return Message.success("性别更新成功");
    }

    /**
     * 修改logo
     */
    @ResponseBody
    @RequestMapping(value = "/edit_logo", method = RequestMethod.POST)
    public Object editLogo(String logoUrl) {
        Member sessionMember=memberService.getCurrent();
        Member dataMember=memberService.find(sessionMember.getId());
        dataMember.setLogo(logoUrl);
        memberService.update(dataMember);
        return Message.success("logo修改成功");
    }



    /**
     * 修改昵称
     */
    @ResponseBody
    @RequestMapping(value = "/edit_nickname", method = RequestMethod.POST)
    public Object editNickname(String nickname) {
        Member sessionMember=memberService.getCurrent();
        Member dataMember=memberService.find(sessionMember.getId());
        dataMember.setNickname(nickname);
        memberService.update(dataMember);
        return Message.success("修改成功");
    }




    /**
     * 修改QQ
     */
    @ResponseBody
    @RequestMapping(value = "/edit_qq", method = RequestMethod.POST)
    public Object edit_qq(String qq) {
        Member sessionMember=memberService.getCurrent();
        Member dataMember=memberService.find(sessionMember.getId());
        dataMember.setQq(qq);
        memberService.update(dataMember);
        return Message.success("修改成功");
    }


    @Autowired
    AreaService areaService;



}
